package com.summer.framework.system.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.summer.framework.base.constant.IntegerConstant;
import com.summer.framework.core.entity.BaseEntity;
import com.summer.framework.system.converter.CategoryConverter;
import com.summer.framework.system.controller.dto.CategoryDTO;
import com.summer.framework.system.entity.Category;
import com.summer.framework.system.mapper.CategoryMapper;
import com.summer.framework.system.service.CategoryService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 数据字典 服务实现类
 * </p>
 *
 * @author Ice
 * @since 2025-09-25
 */
@Service
@RequiredArgsConstructor
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    private final CategoryConverter converter;

    @Override
    public void saveCategory(CategoryDTO dto) {
        Category category = converter.toEntity(dto);
        baseMapper.insert(category);
    }

    @Override
    public CategoryDTO getByCode(String code) {
        LambdaQueryWrapper<Category> query = new LambdaQueryWrapper<>();
        query.eq(Category::getCode, code)
                .eq(BaseEntity::getDeleted, IntegerConstant.ZERO);
        Category category = baseMapper.selectOne(query,false);
        return converter.toDTO(category);
    }
}
